package adapter.combination;

// 目标接口：需要 110V 电压
interface Power110V {
    void output110V();
}

// 被适配者：提供220V 电压
class Power220V {
    public void output220V() {
        System.out.println("提供 220V 电压");
    }
}

// 适配器：将 220V 转换成 110V
class PowerAdapter implements Power110V {
    private final Power220V power220V; // 组合的方式

    public PowerAdapter(Power220V power220V) {
        this.power220V = power220V;
    }

    @Override
    public void output110V() {
        power220V.output220V();     // 先输出 220V
        System.out.println("适配器转换电压：220V -> 110V");
    }
}

// 笔记本电脑，使用 110V 供电
class Laptop {
    private final Power110V power110V;

    public Laptop(Power110V power110V) {
        this.power110V = power110V;
    }

    public void charge() {
        power110V.output110V();
        System.out.println("笔记本充电完成");
    }
}

public class AdapterTest {
    public static void main(String[] args) {
        PowerAdapter adapter = new PowerAdapter(new Power220V());   // 适配器
        Laptop laptop = new Laptop(adapter);                        // 笔记本使用适配器
        laptop.charge();                                            // 充电
    }
}